package com.sky.controller.user;


import com.sky.entity.Setmeal;
import com.sky.result.Result;
import com.sky.service.SetMealService;
import com.sky.vo.DishItemVO;
import io.swagger.annotations.Api;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.cache.annotation.Cacheable;

import java.util.List;

@RestController("userSetMealConttoller")
@Slf4j
@Api(tags = "C端-套餐接口")
@RequestMapping("/user/setmeal")
public class SetmealContoller {
    @Autowired
    private SetMealService setMealService;

    //根据分类id查询套餐,然后使用注解先查询缓存，缓存没有再查询数据库
    @GetMapping("/list")
    @Cacheable(cacheNames = "setMealCache",key = "#categoryId")
    public Result<List<Setmeal>> queryByCategoryId(@RequestParam Long categoryId){
        List<Setmeal> setmealList = setMealService.queryByCategoryId(categoryId);
        return Result.success(setmealList);
    }

    //根据套餐id查询包含的菜品
    @GetMapping("/dish/{id}")
    public Result<List<DishItemVO>> queryBySetMealId(@PathVariable("id") Long setmealId){
        List<DishItemVO> dishItemVOList = setMealService.queryDishBySetMealId(setmealId);
        return Result.success(dishItemVOList);
    }
}
